# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt

from app.models import *

import matlab
import matlab.engine
# Create your views here.
@csrf_exempt

def getRecomendDoctor(request):

    if request.method == "GET":
        return render(request, 'index.html')

    if request.method == "POST":

        selectprovince = request.POST['selectprovince']
        selectcity = request.POST['selectcity']
        selectdisease = request.POST['selectdisease']
        attributes_list = []
        try:
            star = request.POST['inline-checkbox1']
            attributes_list.append(int(star))
        except:
            pass
        try:
            skilled = request.POST['inline-checkbox2']
            attributes_list.append(int(skilled))
        except:
            pass
        try:
            outPatient = request.POST['inline-checkbox3']
            attributes_list.append(int(outPatient))
        except:
            pass
        try:
            attention = request.POST['inline-checkbox4']
            attributes_list.append(int(attention))
        except:
            pass
        try:
            remark = request.POST['inline-checkbox5']
            attributes_list.append(int(remark))
        except:
            pass

        try:
            order = request.POST['inline-checkbox6']
            attributes_list.append(int(order))
        except:
            pass

        try:
            attitude = request.POST['inline-checkbox7']
            attributes_list.append(int(attitude))
        except:
            pass

        disease_id = []
        disease_id.append(int(selectdisease))
        print attributes_list

        eng1 = matlab.engine.connect_matlab()
        doctor_info = eng1.Doctor_Recommend(matlab.double(disease_id), matlab.double(attributes_list)) #doctorid list
        doctors = []
        param_list = set()
        for i in doctor_info:
            try:
                doctor = Doctor.objects.get(pk= i)
                if doctor.DocName in param_list:
                    continue
                param_list.add(doctor.DocName)
                doctors.append(doctor)
            except:
                pass
        return render(request, 'index.html' ,{'doctors':doctors})
